﻿// Projectile.cs

//Using declarations
using System;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;


namespace Midgard
{
    class Projectile
    {
        public static Texture2D texture; // Image representing the Projectile

        // Position of the Projectile relative to the upper left side of the screen
        public Vector2 position;

        // State of the Projectile
        public bool active;

        // The amount of damage the projectile can inflict to an enemy
        public int damage;

        // Represents the viewable boundary of the game
        Rectangle viewport;

        //Used to rotate the star
        float rotation;

        // Get the width of the projectile ship
        public int Width
        {
            get { return texture.Width; }
        }

        // Get the height of the projectile ship
        public int Height
        {
            get { return texture.Height; }
        }

        // Determines how fast the projectile moves
        Vector2 velocity;

        // Factions are used to differentiate projectiles so enemies don't kill each other, etc
        Faction faction;

        public enum Faction
        { player, enemy };

        public Projectile(Texture2D ProjectileSpriteTexture, Vector2 ProjectilePosition, Vector2 ProjectileVelocity,
            Rectangle ViewportRectangle, int ProjectileDamage, float ProjectileRotation, Faction ProjectileFaction)
        {
            texture = ProjectileSpriteTexture;
            position = ProjectilePosition;
            velocity = ProjectileVelocity;
            viewport = ViewportRectangle;
            damage = ProjectileDamage;
            rotation = ProjectileRotation;
            faction = ProjectileFaction;

            /* Initializers */
            Initialize();
        }


        public void Initialize()
        {
            active = true;
        }


        public void Update()
        {
            position.X += velocity.X;
            position.Y += velocity.Y;

            // Deactivate the projectile if it goes out of screen.
           if (position.Y + Height < 0 || position.Y + Height > viewport.Height || 
               position.X + Width < 0 || position.X + Width > viewport.Width)
                active = false;
        }


        public void Draw(SpriteBatch spriteBatch)
        {
            //spriteBatch.Draw(texture, new Rectangle(position.X, position.Y, Width, Height), Color.White, rotation, new Vector2(), SpriteEffects.None, 0f);

            spriteBatch.Draw(texture, position, Color.White);
        }

    }
}
